// @Author EthanScriptOn
// @Desc
package log

import (
	"gitee.com/fatzeng/srf_switch_log/log_define"
	"gitee.com/fatzeng/srf_switch_log/log_format"
	"strings"
)

type LogSnapshot struct {
	Level     log_define.LogLevel
	Key       interface{}
	Value     []interface{}
	CallDepth int
}

func (l *LogSnapshot) TemplateParser(bits []log_define.LogSnapshotOutBit) string {
	builder := strings.Builder{}
	for _, bit := range bits {
		builder.WriteString(l.formatOutputContent(bit, l))
	}
	builder.WriteString("\r\n")
	return builder.String()
}

func (l *LogSnapshot) formatOutputContent(bit log_define.LogSnapshotOutBit, logSnapshot *LogSnapshot) string {
	parserStrategies, err := log_format.GetTemplateParserStrategy()
	if err != nil {
		return ""
	}
	parser, ok := parserStrategies[bit]
	if !ok {
		return ""
	}
	return parser(logSnapshot)
}
